<template>
  <div id="box">
    <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
      <van-swipe-item v-for="(item,index) in swipedata" :key="index">
        <img :src="item">
      </van-swipe-item>
    </van-swipe>


    <div class="flex mar">
      <van-sidebar v-model="active" @change="onChange">
        <van-sidebar-item v-for="item in listdata" :title="item.cname" @click="goDetail(item.tid)"/>
      </van-sidebar>

      <div id="rightbox">
        <div v-for="item in rightdata" :key="item.tid" id="one" >
          <div class="flex">
            <img :src="item.fullSrc">
            <div id="side">
              <div font-size="12px">{{item.tname}}</div>
              <div font-size="16px">¥：{{item.price}}</div>
            </div>
          </div>
        </div>
      </div>

    </div>
  </div>
</template>

<script setup lang="ts">
import { ref,onMounted } from "vue";
import { getCateData } from "../../api"
import { showToast } from 'vant';
import {useRouter} from "vue-router"

let listdata=ref()
let swipedata=ref()
let rightdata=ref()

const active = ref(0);
const router=useRouter()

onMounted(async()=>{
  const {data:{data:{list,swipe}}} = await getCateData()
  //console.log(swipe,list)
  listdata.value=list
  swipedata.value=swipe
  //console.log(listdata.value)
  rightdata.value=listdata.value[0].children
  //console.log(rightdata)
})

const onChange = (index) =>{ 
  //console.log(index)
  rightdata=listdata.value[index].children
  //console.log(rightdata)
  }
function goDetail(tid:number){
  console.log("跳转路径没写");
  //router.push("/detail?tid"+tid)
}

</script>

<style scoped>
html{
  height:100%;
  background-color:#eee;
  display:block
}
#box{
  padding:10px;
  background-color:#eee;
  height:calc(100vh - 2.5946rem);
}
  .my-swipe{
    width:355px;
    height:200px;
  }
  
  .my-swipe .van-swipe-item {
    color: #fff;
    font-size: 20px;
    line-height: 150px;
    text-align: center;
  }
  .my-swipe img{
    width:355px;
    height:100%; 
  }

  .flex{
    display:flex;
    width:100%;
    height:100%;
  }
  .mar{
     margin-top:5px;
  }
  img{
    width:88px;
    height:88px;
  }
  #rightbox{
    flex:1;
    height:100%;
  }
  #one{
    background-color:#fff;
    margin:0 0 5px 5px
  }
  #side{
    display:flex;
    flex-direction:column;
    justify-content:space-between;
  }

</style>
